import sys

import xlrd

from model.OneScoreRankShengNei import OneScoreRankShengNei


# 复制2022年的《省内一分一档表》数据到2023年，因为正式的2023年省内一分一档数据还没出来
def to_copy():
    oneScoreRankShengNei = OneScoreRankShengNei()
    old_year = 2022
    new_year = 2023
    data = oneScoreRankShengNei.getList(old_year)
    total_list = list()
    for index, row in enumerate(data):
        print(index, row)
        row['year'] = new_year
        del row['id']
        total_list.append(row)

    oneScoreRankShengNei.toInsertBatch(total_list)


# 导入2023年文理科省内一分一档表
def import_one_score_rank_like():
    data = xlrd.open_workbook('../static/excel_2023/like_shengnei2023.xls')
    table = data.sheet_by_name('Sheet1')
    rowNum = table.nrows
    colNum = table.ncols
    print(rowNum, colNum)
    oneScoreRankShengNei = OneScoreRankShengNei()
    for i in range(rowNum):
        if i > 2:
            row = dict()
            row['year'] = 2023
            row['type'] = 1  # 文理科 1理科 2文科
            row['score'] = int(table.cell(i, 0).value)
            row['num'] = int(table.cell(i, 1).value)
            row['total_num'] = int(table.cell(i, 2).value)
            row['rank'] = int(table.cell(i, 3).value)
            print(row)
            oneScoreRankShengNei.toInsert(row)


# 导入2023年文理科省内一分一档表
def import_one_score_rank_wenke():
    data = xlrd.open_workbook('../static/excel_2023/wenke_shengnei2023.xls')
    table = data.sheet_by_name('Sheet1')
    rowNum = table.nrows
    colNum = table.ncols
    print(rowNum, colNum)
    oneScoreRankShengNei = OneScoreRankShengNei()
    for i in range(rowNum):
        if i > 2:
            row = dict()
            row['year'] = 2023
            row['type'] = 2  # 文理科 1理科 2文科
            row['score'] = int(table.cell(i, 0).value)
            row['num'] = int(table.cell(i, 1).value)
            row['total_num'] = int(table.cell(i, 2).value)
            row['rank'] = int(table.cell(i, 3).value)
            oneScoreRankShengNei.toInsert(row)


if __name__ == "__main__":
    import_one_score_rank_wenke()
